package com.work.music.dao;

import com.work.music.common.ResponseJson;
import com.work.music.entity.IntegralType;
import java.util.List;

import com.work.music.entity.MusicUser;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

@Repository
public interface IntegralTypeMapper {
    @Delete({
        "delete from music_integral_type",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into music_integral_type (type, `desc`, ",
        "integral)",
        "values (#{type,jdbcType=INTEGER}, #{desc,jdbcType=VARCHAR}, ",
        "#{integral,jdbcType=BIGINT})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insert(IntegralType record);

    @Select({
        "select",
        "id, type, `desc`, integral",
        "from music_integral_type",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="type", property="type", jdbcType=JdbcType.INTEGER),
        @Result(column="desc", property="desc", jdbcType=JdbcType.VARCHAR),
        @Result(column="integral", property="integral", jdbcType=JdbcType.BIGINT)
    })
    IntegralType selectByPrimaryKey(Long id);

    @Select({
        "select",
        "id, type, `desc`, integral",
        "from music_integral_type"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="type", property="type", jdbcType=JdbcType.INTEGER),
        @Result(column="desc", property="desc", jdbcType=JdbcType.VARCHAR),
        @Result(column="integral", property="integral", jdbcType=JdbcType.BIGINT)
    })
    List<IntegralType> selectAll();

    @Update({
        "update music_integral_type",
        "set type = #{type,jdbcType=INTEGER},",
          "`desc` = #{desc,jdbcType=VARCHAR},",
          "integral = #{integral,jdbcType=BIGINT}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(IntegralType record);

    @Select({
            "select",
            "id, type, `desc`, integral",
            "from music_integral_type",
            "where type=#{type,jdbcType=INTEGER}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="type", property="type", jdbcType=JdbcType.INTEGER),
            @Result(column="desc", property="desc", jdbcType=JdbcType.VARCHAR),
            @Result(column="integral", property="integral", jdbcType=JdbcType.BIGINT)
    })
    List<IntegralType> selectIntegralTypeByType(int type);

    /**
     * 获取总条数
     * @param msg
     * @return
     */
    @Select("select count(*) from music_integral_type ${msg}")
    int selectIntegralTypeCount(@Param("msg") String msg);


    /**
     * 获取列表
     * @param msg
     * @param start
     * @param count
     * @return
     */
    @Select("select id,type,`desc`,integral from music_integral_type ${msg} limit #{start},#{count}")
    List<IntegralType> selectIntegralTypeList(@Param("msg") String msg, @Param("start") int start, @Param("count") int count);
}